package club.dataresources.controller;

import club.dataresources.bo.BarberBo;
import club.dataresources.common.R;
import club.dataresources.entity.Barber;
import club.dataresources.entity.BarberOrderedExample;
import club.dataresources.mapper.BarberMapper;
import club.dataresources.service.BarberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;

/**
 * 用户预约理发师 服务
 *
 * @author
 * @create 2018-11-12 10:56
 **/
@RequestMapping(value = "/subscribe")
@Controller
public class SubscribeController {
    @Autowired
    private BarberService barberService;

    @Autowired
    private BarberMapper barberMapper;

    @RequestMapping("/listBarber")
    public @ResponseBody
    R listBarber(
            HttpServletRequest request,
            HttpServletResponse response,
            @RequestBody BarberBo barberBo){
        System.out.println("==================查询显示barberBo===================");
        try {
            List<Barber> liBarber = barberService.listBarber(barberBo.getPage(),barberBo.getRows(),barberBo);
            return R.ok().put("code",200).put("data",liBarber).put("msg","分页显示");
        }catch (Exception e){
            e.printStackTrace();
            return R.error().put("code",500).put("msg","后台服务器异常");
        }
    }

    /**
     * 根据barberId显示理发师未来七天的工作时间预约情况
     * @param barberId
     * @return
     */
    @RequestMapping("/listBwtByBarberId")
    public @ResponseBody
    R listBwtByBarberId(@RequestParam("barberId") Integer barberId){
        System.out.println("===============根据barberId显示理发师未来七天的工作时间预约情况==============");
        try {
            //先根据barberId和date(大于今天)的条件找出是否有预约记录
            BarberOrderedExample example = new BarberOrderedExample();
            BarberOrderedExample.Criteria criteria = example.createCriteria();
            criteria.andBarberIdEqualTo(barberId);
            Date date = new Date();
            criteria.andDateGreaterThan(date);

        }catch (Exception e){

        }
        return null;
    }

    /**
     * 根据barberId和time预约理发师
     * @param request
     * @param response
     * @param barberId
     * @param time
     * @return
     */
    @RequestMapping("/subscribeBarberByBid")
    public @ResponseBody
    R subscribeBarberByBid(
            HttpServletRequest request,
            HttpServletResponse response,
            @RequestParam("barberId") Integer barberId,
            @RequestParam("time") String time){
        System.out.println("=============根据barberId和time预约理发师===========");
        try {
            if(request.getSession().getAttribute("order")!=null){
                //订单修改
            }else{
                //普通预约,还未预定套餐,重定向到选择套餐页面
                response.sendRedirect("/listMenu");
                return R.ok().put("code",200).put("msg","普通预约,还未预定套餐,重定向到选择套餐页面");
            }
        }catch (Exception e){

        }
        return null;
    }
}
